<template>
  <div class="ht-search-form">
    <div v-if="false">
      <MyTemp></MyTemp>
    </div>

    <p class="ht-form-title">验度明细</p>

    <ht-table
      class="ht-table-no-border"
      :data="state.dataSource"
      style="width: 100%; margin-top: 12px"
      border
      :hide-order="true"
      :hide-page="true"
      highlight-current-row
      :columns="columns"
    >
    </ht-table>
  </div>
</template>
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import MyTemp from './myTemp.vue';
import Mock from 'mockjs';

import moment from 'moment';
import { Column } from 'htui-yllkbz/src/packages/type';
interface State {
  /** 数据状态 */

  loading: boolean;

  dataSource: any;
  testData: any;
}
@Component({
  components: {
    MyTemp,
  },
})
export default class Index extends Vue {
  /** 数据 */
  state: State = {
    loading: false,

    dataSource: [],
    testData: [],
  };
  /** 生命周期 */
  mounted() {
    //Mock数据

    //根据起止时间生成随机时间
    const randomDate = (startDate: any, endDate: any) => {
      const date = new Date(+startDate + Math.random() * (endDate - startDate));
      const hour = (0 + Math.random() * (23 - 0)) | 0;
      const minute = (0 + Math.random() * (59 - 0)) | 0;
      const second = (0 + Math.random() * (59 - 0)) | 0;
      date.setHours(hour);
      date.setMinutes(minute);
      date.setSeconds(second);
      return date;
    };
    // 生产当月的开始日期
    const startDate = new Date('2019-06-01 00:00:00');
    // 截止日期
    const endDate = new Date('2022-10-10 17:00:00');
    // 生产当月的开始日期
    const startDate1 = new Date('2023-01-01 00:00:00');
    // 截止日期
    const endDate1 = new Date('2023-10-10 17:00:00');
    const testData = [];
    for (let i = 0; i < 100; i++) {
      testData.push(
        Mock.mock({
          enum: i,
          id: '@id',
          userName: '@cname',
          'age|1-99': 1,
          'gender|1': ['男', '女'],
          addr: '@county(true)',
          tel: /^1[3456789]\d{9}/,
          emil: '@email',
          'alcohol|60-70.1-10': 1,
          'temperature|10-20.1-10': 1,
          'alcoholproof|60-70.1-10': 1,
        })
      );
      testData[i].datetime = moment(randomDate(startDate, endDate)).format(
        'YYYY-MM-DD HH:mm'
      );
      testData[i].datetime1 = moment(randomDate(startDate1, endDate1)).format(
        'YYYY-MM-DD HH:mm'
      );
    }

    this.state.testData = testData;

    this.createData();
  }
  // 构建数据

  createData() {
    // 生成0,1的随机数
    const typeArr = ['移出', '移入'];

    // 定义厂区
    const factoryName = ['总部', '古井', '张集', '智能院', '产业园'];
    const storehouses = [
      '3部收酒站',
      '预混区',
      '勾调区',
      '净酒区',
      '5#库',
      '6#库',
      '7#库',
      '8#库',
      '9#库',
      '冷冻过滤',
    ];
    // 定义酒品名称，酒品代码
    const wine = [
      {
        wineName: '36度特勾',
        wineCode: '300000-01',
      },
      {
        wineName: '55度特勾',
        wineCode: '300000-02',
      },
      {
        wineName: '63度明清窖池酒',
        wineCode: '300000-03',
      },
      {
        wineName: 'N50-4Y',
        wineCode: '300000-04',
      },
      {
        wineName: 'N52-1J',
        wineCode: '300000-05',
      },
      {
        wineName: 'N52-4Y',
        wineCode: '300000-06',
      },
      {
        wineName: 'T63-4L',
        wineCode: '300000-07',
      },
      {
        wineName: 'BH-01',
        wineCode: '300072',
      },
      {
        wineName: 'GB38-2T',
        wineCode: '300035',
      },
      {
        wineName: 'GB42-2T',
        wineCode: '300034',
      },
      {
        wineName: 'GB45-2T',
        wineCode: '300033',
      },
      {
        wineName: 'GB50-2T',
        wineCode: '300032',
      },
      {
        wineName: 'GC38-3T',
        wineCode: '300040',
      },
      {
        wineName: 'GC42-3T',
        wineCode: '300038',
      },
      {
        wineName: 'GC45-3T',
        wineCode: '300037',
      },
      {
        wineName: 'GC50-3T',
        wineCode: '300036',
      },
      {
        wineName: 'MA38-1S',
        wineCode: '300022',
      },
      {
        wineName: 'MA45-1S',
        wineCode: '300020',
      },
      {
        wineName: 'MA45-1W',
        wineCode: '300024',
      },
      {
        wineName: 'MA55-1S',
        wineCode: '300018',
      },
      {
        wineName: 'MB38-2P',
        wineCode: '300030',
      },
      {
        wineName: 'MB40.6-2P',
        wineCode: '300029',
      },
      {
        wineName: 'MB42-1P',
        wineCode: '301002',
      },
      {
        wineName: 'MB42-2P',
        wineCode: '300028',
      },
      {
        wineName: 'MB45-2P',
        wineCode: '300027',
      },
      {
        wineName: 'MB50-1P',
        wineCode: '301003',
      },
      {
        wineName: 'MB50-2P',
        wineCode: '300026',
      },
      {
        wineName: 'MB55-2P',
        wineCode: '300025',
      },
      {
        wineName: 'MB60-2P',
        wineCode: '300271',
      },
      {
        wineName: 'MB72-2P',
        wineCode: '300065',
      },
      {
        wineName: 'N45-3Y',
        wineCode: '300059',
      },
      {
        wineName: 'N52-ZD',
        wineCode: '300063',
      },
      {
        wineName: 'N60-4Y',
        wineCode: '300056',
      },
    ];
    // 定义容器
    const container = ['B酒罐', 'C酒罐', 'D酒罐', '缓存罐', '大储存罐'];

    // 循环次数
    const count = Math.floor(Math.random() * 20);
    for (let index = 0; index < count; index++) {
      const TypeIndex = Math.floor(Math.random() * 2);
      // 生成0,4的随机数
      const factoryNameIndex = Math.floor(Math.random() * 2);
      // 生成0,9的随机数
      const storehousesIndex = Math.floor(Math.random() * 10);
      // 生成0,34的随机数
      const wineIndex = Math.floor(Math.random() * 33);
      const obj = {
        type: `${typeArr[TypeIndex]}`,
        factoryName: `${factoryName[factoryNameIndex]}`,
        storehouses: `${storehouses[storehousesIndex]}`,
        sapName: `${container[factoryNameIndex]}`,
        sapCode: `${1 + '-' + this.changeNumber(index)}`,
        wineName: `${wine[wineIndex]?.wineName}`,
        wineCode: `${wine[wineIndex]?.wineCode}`,
        createTime: this.state.testData[index]?.datetime,
        alcohol: this.state.testData[index]?.alcohol.toFixed(1) + ' vol%',
        temperature: this.state.testData[index]?.temperature.toFixed(1) + ' ℃',
        alcoholproof:
          this.state.testData[index]?.alcoholproof.toFixed(1) + ' vol%',
        inspector: this.state.testData[index]?.userName,
        degreeTime: this.state.testData[index]?.datetime1,
      };

      this.state.dataSource.push(obj);
    }
  }
  /** 方法 */
  // 自动补0

  changeNumber(num: number) {
    if (num < 10) {
      return '00' + num;
    } else if (num < 100) {
      return '0' + num;
    } else {
      return num.toString();
    }
  }
  /** 监听 */
  /** 计算属性 */
  /** 计算属性 */
  get columns(): Column[] {
    return [
      { key: 'type', title: '类型' },
      { key: 'factoryName', title: '厂区' },
      //
      { key: 'storehouses', title: '酒库' },
      { key: 'sapName', title: '容器' },

      { key: 'sapCode', title: '容器编号' },

      { key: 'wineName', title: '酒品名称' },
      { key: 'wineCode', title: '酒品代码' },
      { key: 'createTime', title: '生产年月' },
      //

      //

      { key: 'alcohol', title: '酒度' },
      { key: 'temperature', title: '温度' },
      { key: 'alcoholproof', title: '标准酒度' },
      { key: 'inspector', title: '验度人' },
      { key: 'degreeTime', title: '验度时间' },
    ];
  }
}
</script>
<style lang="scss" scoped></style>
